<?php

function getSiteMeta($domain){
	$tags = get_meta_tags($domain);
	
	if (sizeof($tags) == 0){
		echo '<tr><td align="center"> No META information was found! </td></tr>';
	}
	
	foreach ($tags as $key=>$value) {
		echo "<tr><td class='key'>$key: </td><td class='values'>$value</td></tr>";
	}

}

$domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>MicroMetaSpider - Check website META information</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="main">
      <div class="caption">MICRO META SPIDER</div>
      <div id="icon">&nbsp;</div>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain" id="domain">
        <table width="100%">
          <tr><td>Site URL: <input class="text" name="domainname" type="text" size="67" value="<?php echo $domainbase; ?>" /></td></tr>
          <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="Get META" /></td></tr>
        </table>  
      </form>
<?php    
    if (isset($_POST['submitBtn'])){
        $domainbase = str_replace("http://","",strtolower($domainbase));

?>
      <div class="caption">META DATA:</div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <!-- <table width="100%" border='1'> -->
		<?php
			//getSiteMeta("http://".$domainbase);

			/*
			$docs = new DOMDocument();

			information needed:

			meta:
				title
				url - the URL of the file pasted 
				description or DESCRIPTION
			link:
				image_src


			$docs = new DOMDocument();
			@$docs->loadHTMLFile("http://".$domainbase);

			$tags = $docs->getElementsByTagName('meta');
			if (sizeof($tags) == 0){
				echo 'No META information was found!';
			}

			foreach ($tags as $tag) {
				echo $tag->getAttribute('name').' | '.$tag->getAttribute('content')."<br/>";
			}

			$tags = $docs->getElementsByTagName('link');
			if (sizeof($tags) == 0){
					echo 'No link information was found!';
				}
			foreach ($tags as $tag) {
					echo $tag->getAttribute('rel').' | '.$tag->getAttribute('href')."<br/>";
					$count++;
			}
			*/
			
			function expand($arr)
			{
				for($i=0,$len=sizeof($arr);$i<$len;$i++)
				{
					if(is_array($arr[$i]))
					{
						echo '<br/>';
						expand($arr[$i]);
						echo '<br/>';
					}
					else
					{
						echo '<br/>'.($i).'->'.$arr[$i].'<br/>';
					}
				}
			}
			
			$meta = get_meta_tags("http://".$domainbase);
			$page = file_get_contents("http://".$domainbase);

			//print_r($meta);
			//$txt = '<br/>'.$meta['title'];
			//$txt .= '<br/>'.$meta['description'];
			$txt="";

			function getTitle(&$page){
				$idx1 = stripos($page,"<title>")+7;
				$idx2 = stripos($page,"</title>",$idx1);
				$title = substr($page,$idx1,$idx2-$idx1);
				//echo 'getTitle():'.$title.'<br/>';
				return $title;
			}

			function getDescription(&$meta){
				//echo 'getDescription():'.$meta['description'].'<br/>';
				return $meta['description'];
			}

			function getImageSource(&$page){
				$pattern = "|<link[^>]+rel=\"image_src\"[^>]+href=\"([^\"]*)\"[^>]+>|i";
				preg_match_all($pattern, $page, $matches, PREG_SET_ORDER);
				//echo 'getImageSource():'.$matches[0][1].'<br/>';
				return $matches[0][1];	
			}

			$pattern = "|<link[^>]+rel=\"image_src\"[^>]+href=\"([^\"]*)\"[^>]+>|i";

			$txt = getTitle($page).'<br/>';
			$txt .= getDescription($meta).'<br/>';
			$txt .= getImageSource($page).'<br/>';
						
			echo $txt;
		?>
     </div>
<br/>

<?php            
    }
?>
	<div id="source">Micro Meta Spider 1.0</div>
    </div>
</body>   
